Skip to content

Conversation

@thomasiles
Copy link
Contributor

@thomasiles thomasiles commented Nov 17, 2025

Caution

This is a spike and should not be merged to main.

A spike for routing in Welsh forms

Trello card: https://trello.com/c/ru3OyRAX/2686-timeboxed-2-days-spike-how-bilingual-forms-will-work-with-routing-branching

This is the code needed for admin to create forms with welsh translations in order to test routing.

See alphagov/forms-runner#1729

Things to consider when reviewing

  • Ensure that you consider the wider context.
  • Does it work when run on your machine?
  • Is it clear what the code is doing?
  • Do the commit messages explain why the changes were made?
  • Are there all the unit tests needed?
  • Do the end to end tests need updating before these changes will pass?
  • Has all relevant documentation been updated?

This commit syncs welsh FormDocuments with the English ones.

There are two heavy handed simplifications here:
- Welsh forms are synced in lock-step with English forms. When creating
  a live version of a form, the Welsh version is made live too. This
  doesn't match the design, where the two are independent.
- Any missing text in the Welsh form is filled in from the English
  version. This makes sense for testing and draft forms but it's not how
  we would handle live forms unless we knew we had validation in place.

There is quite a bit of duplication here. There is probably a better way
to do this.
To allow testing routes, we allow the welsh translation to have selection options.

This takes the simplest approach, presenting the selection options as
text fields under the page fields.

We need to take care when doing this to make sure the Welsh translation
have answer settings which match the English version.

The only text in any page's answer settings which needs to be translated
are the selection options. When assigning attributes, we check to see if
the Welsh has answer_settings. If it doesn't we copy the English
answer_settings and then reset the selection options to be blank.

When saving the translation, we need to copy the selection options from
the Welsh answer_settings to the English answer_settings.

This code is hacky and shouldn't be used in production. We need to take
more care about keeping them in sync and consider how to handle new
options being added before the translations are saved.

The view itself doesn't use the values directly from the Welsh
answer_settings and currently it relies on position, which I think is
wrong.

We modify the Page model to add value to the selection options. We use
this as a backstop to add the English name when welsh translations are
missing.

I think the whole thing could be more coherent if we keep the Welsh
answer_settings in sync with the English answer_settings and use this
value directly when creating the FormDocument.

We would still need to handle the adding/removing of selection options
outside of the welsh translation page.
We broke some tests by changing the output of
Page.as_form_document_step.

We could have avoided this by only changing the output for welsh forms.
Add Welsh to available languages when saving translation.

Without this, the form won't by available in Welsh, FormDocuments won't
be created and the runner won't know to offer a link to the Welsh
version.
@thomasiles thomasiles force-pushed the welsh-form-routing-spike branch from 96fc815 to bb1a843 Compare November 17, 2025 16:15
@sonarqubecloud
Copy link

@github-actions
Copy link

🎉 A review copy of this PR has been deployed! You can reach it at: https://pr-2360.admin.review.forms.service.gov.uk/

It may take 5 minutes or so for the application to be fully deployed and working. If it still isn't ready
after 5 minutes, there may be something wrong with the ECS task. You will need to go to the integration AWS account
to debug, or otherwise ask an infrastructure person.

For the sign in details and more information, see the review apps wiki page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants